<template>
  <div style="padding: 8px;">
    <el-table :data="records" size="small" style="width: 100%">
      <el-table-column
        v-for="col in tableColumns"
        :prop="col.prop"
        :label="col.label"
        :width="col.width"
        :key="col.prop"
      >
        <template slot-scope="scope">
          <span v-if="col.type === 'time'"> {{ scope.row[col.prop] | format }}</span>
          <span v-else>{{
            col.format ? col.format(scope.row[col.prop]) : scope.row[col.prop]
          }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapState } from "vuex";
const translateStatus = status => {
  return status ? "停止" : "运行";
};
export default {
  name: "WorkflowChildren",
  filters: {
    translateStatus
  },
  data() {
    return {
      records: [],
      tableColumns: [
        {
          prop: "id",
          label: "工作流ID",
          width: "180"
        },
        {
          prop: "name",
          label: "工作流名称"
          // width: "180"
        },
        {
          prop: "is_paused",
          label: "调度状态",
          // width: "80",
          format: translateStatus
        },
        {
          prop: "interval",
          label: "调度周期"
          // width: "180"
        },
        {
          prop: "cron",
          label: "cron",
          width: "200"
        },
        {
          prop: "start_time",
          label: "调度开始时间",
          // width: "180",
          type: "time"
        },
        {
          prop: "end_time",
          label: "调度结束时间",
          // width: "180",
          type: "time"
        }
      ]
    };
  },
  computed: {
    ...mapState({
      currentTab: ({ data }) => {
        return data.currentTab || {};
      }
    })
  },
  watch: {
    ["currentTab.id"](newval) {
      this.initData();
    }
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.$http.workflow.getWorkflowChildren({ id: this.currentTab.id }).then(res => {
        this.records = res;
      });
    },
    handleStop(index, row) {},
    downloadlog(index, row) {}
  }
};
</script>
